<?php
require_once './connect.php';
//处理数据
//{dep_name: "产科", doctors: ["医生一", "医生2"]}弃
//{dep_id:"",doctors:[doc_id]}
//{dep_name:"",doctors:[doc_name]}
//科室
$sql = "SELECT dep_name,dep_id FROM _department";
$result = $conn->query($sql);
$datalist=array();
$datalisttwo=array();
$_doctorsname=array();
$_doctorsid=array();
if($result->num_rows>0){
    while($row=$result->fetch_assoc()){
        $dep_id=$row['dep_id'];
        //医生
        $sql = "SELECT doc_id,doc_name FROM _doctor where dep_id='$dep_id'";
        $resulttwo = $conn->query($sql);
        if($resulttwo->num_rows>0) {
            while ($rowtwo = $resulttwo->fetch_assoc()) {
                $doc_name = $rowtwo['doc_name'];
                $doc_id = $rowtwo['doc_id'];
                array_push($_doctorsname,$doc_name);
                array_push($_doctorsid,$doc_id);
            }
        }
        $datasingle=array('dep_name'=>$row['dep_name'],'doctors'=>$_doctorsname);
        array_push($datalist,$datasingle);
        $datasingle=array('dep_id'=>$row['dep_id'],'doctors'=>$_doctorsid);
        array_push($datalisttwo,$datasingle);
        $_doctorsname=array();
        $_doctorsid=array();
    }
}


$datalist=array('dataList' => $datalist,'dataListTwo'=>$datalisttwo);
$response=array(
    'resultCode'=>'0',
    'resultObject'=> $datalist,
    'resultMsg'=>'成功'
);
//echo 'test';
echo json_encode($response);
$conn->close();
?>